home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / driverss.zip / PKTADDR.ASM < prev    next >
Assembly Source File  |  1991-03-25  |  4KB  |  185 lines

  1. version    equ    1
  2.  
  3. ;  Russell Nelson, Clarkson University.  September 14, 1989
  4. ;  Copyright, 1989, Russell Nelson
  5.  
  6. ;   This program is free software; you can redistribute it and/or modify
  7. ;   it under the terms of the GNU General Public License as published by
  8. ;   the Free Software Foundation, version 1.
  9. ;
  10. ;   This program is distributed in the hope that it will be useful,
  11. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;   GNU General Public License for more details.
  14. ;
  15. ;   You should have received a copy of the GNU General Public License
  16. ;   along with this program; if not, write to the Free Software
  17. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     include    defs.asm
  20.  
  21. code    segment word public
  22.     assume    cs:code, ds:code
  23.  
  24.     org    80h
  25. phd_dioa    label    byte
  26.  
  27.     org    100h
  28. start:
  29.     jmp    start_1
  30.  
  31. copyleft_msg    label    byte
  32.  db "Packet address version ",'0'+majver,".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  33.  db "This program is free software; see the file COPYING for details.",CR,LF
  34.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  35. crlf_msg    db    CR,LF,'$'
  36.  
  37. int_pkt    macro
  38.     pushf
  39.     cli
  40.     call    their_isr
  41.     endm
  42.  
  43. their_isr    dd    ?
  44. packet_int_no    db    ?,?,?,?
  45. ether_bdcst    db    EADDR_LEN dup(-1)    ;ethernet broadcast address.
  46. ether_addr    db    EADDR_LEN dup(-1)
  47.  
  48. handle        dw    ?
  49.  
  50. bogus_type    db    0,0        ;totally bogus type code.
  51.  
  52. signature    db    'PKT DRVR',0
  53. signature_len    equ    $-signature
  54. no_signature_msg    db    "No packet driver at that address",'$'
  55. usage_msg    db    "usage: pktaddr <packet_int_no> [<addr>]",'$'
  56.  
  57. eaddr_msg    db    "My Ethernet address is ",'$'
  58.  
  59. usage_error:
  60.     mov    dx,offset usage_msg
  61. error:
  62.     mov    ah,9
  63.     int    21h
  64.     int    20h
  65.  
  66. start_1:
  67.     cld
  68.  
  69.     mov    dx,offset copyleft_msg
  70.     mov    ah,9
  71.     int    21h
  72.  
  73.     mov    si,offset phd_dioa+1
  74.     cmp    byte ptr [si],CR    ;end of line?
  75.     je    usage_error
  76.  
  77.     mov    di,offset packet_int_no
  78.     call    get_number
  79.  
  80.     mov    di,offset ether_addr
  81.     push    ds
  82.     pop    es
  83.     call    get_eaddr
  84.  
  85.     mov    ah,35h            ;get their packet interrupt.
  86.     mov    al,packet_int_no
  87.     int    21h
  88.     mov    their_isr.offs,bx
  89.     mov    their_isr.segm,es
  90.  
  91.     lea    di,3[bx]
  92.     mov    si,offset signature
  93.     mov    cx,signature_len
  94.     repe    cmpsb
  95.     je    have_signature
  96.     mov    dx,offset no_signature_msg
  97.     jmp    error
  98. have_signature:
  99.  
  100.     push    ds
  101.     pop    es
  102.     mov    cx,EADDR_LEN
  103.     mov    si,offset ether_addr
  104.     mov    di,offset ether_bdcst
  105.     repe    cmpsb
  106.     je    get_mode        ;no address specified.
  107.  
  108.     mov    ah,25            ;set the ethernet address.
  109.     mov    di,offset ether_addr
  110.     mov    cx,EADDR_LEN
  111.     int_pkt
  112.     call    fatal_error
  113.     jmp    okay
  114. get_mode:
  115.     mov    ah,2            ;access all packets.
  116.     mov    al,1            ;Ethernet class.
  117.     mov    bx,-1            ;generic type.
  118.     mov    dl,0            ;generic number.
  119.     mov    cx,2            ;use a type length of 2
  120.     mov    si,offset bogus_type
  121.     push    cs            ;es:di -> our receiver.
  122.     pop    es
  123.     mov    di,offset our_recv
  124.     int_pkt
  125.     call    fatal_error
  126.     mov    handle,ax
  127.  
  128.     mov    ah,6            ;get the ethernet address.
  129.     mov    di,offset ether_addr
  130.     mov    cx,EADDR_LEN
  131.     mov    bx,handle
  132.     int_pkt
  133.     jc    bad
  134.  
  135.     mov    dx,offset eaddr_msg
  136.     mov    ah,9
  137.     int    21h
  138.  
  139.     mov    si,offset ether_addr
  140.     call    print_ether_addr
  141.  
  142.     mov    dx,offset crlf_msg    ;can't depend on DOS to newline for us.
  143.     mov    ah,9
  144.     int    21h
  145.     jmp    short now_close
  146. bad:
  147.     call    print_error
  148. now_close:
  149.     mov    ah,3            ;release_type
  150.     mov    bx,handle
  151.     int_pkt
  152.     call    fatal_error
  153.  
  154. okay:
  155.     int    20h
  156.  
  157.  
  158. our_recv:
  159.     or    ax,ax            ;first or second call?
  160.     jne    our_recv_1        ;second -- we ignore the packet
  161.     push    cs
  162.     pop    es
  163.     mov    di,offset our_buffer
  164. our_recv_1:
  165.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  166.  
  167.  
  168.     include    printea.asm
  169.  
  170.     assume    ds:code
  171.  
  172.     include    pkterr.asm
  173.     include    getea.asm
  174.     include    getnum.asm
  175.     include    skipblk.asm
  176.     include    getdig.asm
  177.     include    digout.asm
  178.     include    chrout.asm
  179.  
  180. our_buffer    label    byte
  181.  
  182. code    ends
  183.  
  184.     end    start
  185.